<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
div{
    width: 100px;
    height: 100px;
    background-color: rgb(56, 5, 5);
        color: #fff;
    text-align: center;
    line-height: 100vh;
    font-size: 30px;
        }
</style>
<body>
    <div>广告</div>
    <span class="timer">计时器</span>
    <script>
    var timer = 5;
    var interval = setInterval(function(){
        document.querySelector('.timer').innerHTML = timer;
        timer--;
        if(timer < 0){
            clearInterval(interval);
            document.querySelector('div').style.display = 'none'; 
        }
    }, 1000);

    setTimeout(function(){
        clearInterval(interval);
        document.querySelector('div').style.display = 'none'; 
    }, 5000);
</script>

</body>
</html>